package util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @classname:DateUtil
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/3 22:35
 * @version: 0.1
 * @since:1.8
 */
public class DateUtil {
    //私有化构造方法使其变成工具类不能被创建
    private DateUtil() {
    }

    public static int getDuringTime(String borrowTime, String returnTime, String patten) {
        DateFormat date = new SimpleDateFormat(patten);

        try {
            Date borrowDateTime = date.parse(borrowTime);
            Date returnDateTime = date.parse(returnTime);
            long duringtime = returnDateTime.getTime() - borrowDateTime.getTime();
            //返回值为int毫秒数值强制转换成int类型
            return (int) (duringtime / 3600 / 1000);

        } catch (ParseException e) {
            e.printStackTrace();
        }

        return -1;
    }


}
